import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';


enum AgreementType {
  offerPrice,
  payBond,
}

//同意协议
class Agreement extends StatefulWidget {
  Function? onChanged;
  bool select;
  AgreementType agreementType;

  Agreement(
      {Key? key,
      this.onChanged,
      this.select: false,
      this.agreementType: AgreementType.offerPrice})
      : super(key: key);

  @override
  State<Agreement> createState() => _AgreementState();
}

class _AgreementState extends State<Agreement> {
  bool select = false;

  String tips = '回流买家须知';

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    select = widget.select;
  }

  onTap() {
    
  }

  @override
  void didUpdateWidget(covariant Agreement oldWidget) {
    if (oldWidget.select != widget.select) {
      select = widget.select;
      if (mounted) setState(() {});
    }
    super.didUpdateWidget(oldWidget);
  }

  @override
  Widget build(BuildContext context) {
    return Row(
      crossAxisAlignment: CrossAxisAlignment.center,
      children: [
        GestureDetector(
          behavior: HitTestBehavior.opaque,
          child: Container(
            width: 15.w,
            height: 15.w,
            margin: EdgeInsets.symmetric(horizontal: 10.w),
            child: Center(
              child: Icon(
                Icons.check_outlined,
                color: select ? Color(0xFFFEBA07) : Colors.transparent,
                size: 11.w,
              ),
            ),
            decoration: BoxDecoration(
                borderRadius: BorderRadius.circular(2),
                border: Border.all(
                    width: 1.w,
                    color: select ? Color(0xFFFEBA07) : Color(0xFF999999))),
          ),
          onTap: () {
            setState(() {
              select = !select;
              widget.onChanged!(select);
            });
          },
        ),
        Text(
          "我已经阅读并同意",
          style: TextStyle(fontSize: 12.sp, color: Color(0xFF999999)),
        ),
        InkWell(
          child: Text(
            "《$tips》",
            style: TextStyle(fontSize: 12.sp, color: Color(0xFF037AFF)),
          ),
          onTap: onTap,
        )
      ],
    );
  }
}
